﻿using System;
using System.Linq.Expressions;

namespace NMapper
{
    public class ValueMapping<TDatabaseEntity, TOutput, TDbValue, TOutputValue> : ISelectors<TDatabaseEntity, TOutput, TDbValue, TOutputValue>
    {
        private Func<TDatabaseEntity, TDbValue> dbSelector;
        private Func<TOutput, TOutputValue> outputSelector;

        public ValueMapping(Func<TDatabaseEntity, TDbValue> dbSelector, Func<TOutput, TOutputValue> outputSelector)
        {
            this.dbSelector = dbSelector;
            this.outputSelector = outputSelector;
        }

        LambdaExpression IDbSelector.DbSelectorExpression
        {
            get { throw new NotImplementedException(); }
        }

        LambdaExpression IOutputSelector.OutputSelectorExpression
        {
            get { throw new NotImplementedException(); }
        }

        Func<object, object> IDbSelector.DbSelector
        {
            get { return x => dbSelector((TDatabaseEntity)x); }
        }

        public Func<TDatabaseEntity, TDbValue> DbSelector
        {
            get { return dbSelector; }
        }

        Func<object, object> IOutputSelector.OutputSelector
        {
            get { return x => outputSelector((TOutput)x); }
        }

        public Func<TOutput, TOutputValue> OutputSelector
        {
            get { return outputSelector; }
        }
    }
}